package com.mall.manager.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.mall.untils.MapUtil;
import com.mall.untils.ScheduleJob;

@Service
public class ScheduleJobService {

	Logger logger = Logger.getLogger(ScheduleJobService.class);
	
	@Resource
	JdbcTemplate jdbcTemplate;
	
	public List<ScheduleJob> findScheduleJob(){
		List<ScheduleJob> sche = new ArrayList<ScheduleJob>();
		try{
			String sql = "select id,create_time as createTime,update_time as updateTime,job_name as jobName,job_group as jobGroup,job_status as jobStatus,cron_expression as cronExpression,description,bean_class as beanClass,bean_name as beanName,is_concurrent as isConcurrent,method_name as methodName from t_schedule_job";
			List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
			for(Map<String,Object> map:list){
				ScheduleJob job = new ScheduleJob();
				job.setId(MapUtil.getInteger(map, "id"));
				job.setJobName(MapUtil.getStringValue(map, "jobName"));
				job.setJobGroup(MapUtil.getStringValue(map, "jobGroup"));
				job.setJobStatus(MapUtil.getInteger(map, "jobStatus")==0?true:false);
				job.setIsConcurrent(MapUtil.getInteger(map, "isConcurrent")==0?true:false);
				job.setBeanClass(MapUtil.getStringValue(map, "beanClass"));
				job.setBeanName(MapUtil.getStringValue(map, "beanName"));
				job.setCronExpression(MapUtil.getStringValue(map, "cronExpression"));
				job.setMethodName(MapUtil.getStringValue(map, "methodName"));
				job.setDescription(MapUtil.getStringValue(map, "description"));
				sche.add(job);
			}
		}catch(Exception e){
			logger.info("查询定时任务出现异常："+e.getMessage());
		}
		return sche;
	}
}
